home *** CD-ROM | disk | FTP | other *** search
- #include "speech.proto.h"
- #include "rsinterf.proto.h"
- #include "rsdefs.h"
- #include <Errors.h>
- #include <Gestalt.h>
- #include <Memory.h>
- #include <Menus.h>
-
-
- Boolean SpeakSelectedText(short w)
- {
- Boolean isSpeaking = false;
-
- do {
-
- OSErr err;
- long response;
- Handle newSpeechText;
-
- /* Is the Speech Manager present? */
-
- err = Gestalt(gestaltSpeechAttr, &response);
- if (noErr != err || !((1L << gestaltSpeechMgrPresent) & response)) {
- break;
- }
-
- /* Is there any text selected? */
-
- newSpeechText = RSGetTextSel(w, 0);
- if (nil == newSpeechText) {
- break;
- }
-
-
- do {
- Size numberSpeechTextBytes;
-
- /* Get a speech channel */
-
- if (nil == gSpeechChannel) {
- MoveHHi((Handle)gVoices);
- HLock((Handle)gVoices);
- err = NewSpeechChannel(&(*gVoices)[gSelectedVoiceIndex], &gSpeechChannel);
- HUnlock((Handle)gVoices);
- if (noErr != err) {
- break;
- }
- }
-
- /* Start speaking the new text */
-
- MoveHHi(newSpeechText);
- HLock(newSpeechText);
- numberSpeechTextBytes = GetHandleSize(newSpeechText);
-
- err = SpeakText(gSpeechChannel, *newSpeechText, numberSpeechTextBytes);
-
- /* Flash the selection, and fix the menu */
-
- FlashSelection(w);
- EnableItem(myMenus[Speech], SPStopSpeaking);
-
- /*
-
- /* Free the old buffer, and set the global to the new one */
-
- DisposeHandle(gSpeechText);
- gSpeechText = newSpeechText;
-
- isSpeaking = true;
-
- } while (false);
-
- if (!isSpeaking) {
- if (nil != newSpeechText) {
- DisposeHandle(newSpeechText);
- }
- }
-
- } while (false);
-
- return isSpeaking;
- }
-
-